#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：setting.py 
@File ：handle_exceptions.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/6/4 上午8:01 
"""

import json
from functools import wraps


def handle_exceptions(func):
	@wraps(func)
	def wrapper(*args, **kwargs):
		try:
			return func(*args, **kwargs)
		except Exception as e:
			print(f'Error in {func.__name__}: {e}')
			error_message = f'Error in {func.__name__}: {e}'
			error_dict = {'state': 'Failure', 'message': error_message}
			error_text = json.dumps(error_dict, ensure_ascii=False, default=lambda x: error_dict.keys())
			return error_text

	return wrapper
